//
//  MovieListViewController.m
//  UI_豆瓣
//
//  Created by WangZe on 15/10/12.
//  Copyright © 2015年 王泽龙. All rights reserved.
//

#import "MovieListViewController.h"
//#import "MBProgressHUD.h"
#import "NetWorkingTool.h"
#import "MovieList.h"
#import "MovieListCell.h"
#import "UIImageView+WebCache.h"
#import "MovieDetailsViewController.h"
#import "OtherMovieViewController.h"
@interface MovieListViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *mvTableView;
//@property(nonatomic, retain)MBProgressHUD *hud;
@property(nonatomic, retain)NSMutableArray *mvArr;
@end

@implementation MovieListViewController
- (void)dealloc
{
    [_mvTableView release];
    [super dealloc];
}
- (void)createData
{
    self.mvArr = [NSMutableArray array];
    [NetWorkingTool getNetWorking:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php" block:^(id result) {
        NSDictionary *dic = result;
        NSArray *arr = dic[@"result"];
        for (NSDictionary *tempdic in arr) {
            MovieList *mv = [[MovieList alloc] init];
            [mv setValuesForKeysWithDictionary:tempdic];
            [self.mvArr addObject:mv];
        }
        [self.mvTableView reloadData];
//        self.hud.hidden = YES;
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.6
    self.mvTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.mvTableView];
    [_mvTableView release];
    self.mvTableView.delegate = self;
    self.mvTableView.dataSource = self;
    self.mvTableView.rowHeight = 200;
    self.title = @"电影";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:87 / 255.0 green:137 / 255.0 blue:157 / 255.0 alpha:1];
    [self createData];
//    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"九宫格" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    
    
    
}
- (void)click:(UIBarButtonItem *)button
{
    OtherMovieViewController *otherMovieVC = [[OtherMovieViewController alloc] init];
    [self.navigationController pushViewController:otherMovieVC animated:YES];
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MovieDetailsViewController *mvDVC = [[MovieDetailsViewController alloc] init];
    [self.navigationController pushViewController:mvDVC animated:YES];
    MovieList *mv = self.mvArr[indexPath.row];
    mvDVC.movieID = mv.movieId;
    mvDVC.tempMovie = mv;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mvArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *reuse = @"reuse";
    MovieListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[MovieListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
    }
    MovieList *mv = self.mvArr[indexPath.row];
    
    [cell.mvimageView sd_setImageWithURL:[NSURL URLWithString:mv.pic_url]];
    cell.mvName.text = mv.movieName;
    
    return cell;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
